package main

import (
	"fmt"
	"github.com/micro/go-micro/config"
	"github.com/micro/go-micro/config/source/env"
	"github.com/micro/go-micro/config/source/flag"
)

func main() {


	if err := config.Load(flag.NewSource());err != nil {
		fmt.Errorf("err : %v",err)
	}
	err := config.LoadFile("/home/zhang/workspace/learning/micro/config/config.json")
	if err != nil {
		fmt.Errorf("err : %v",err)
	}


	if err := config.Load(env.NewSource(),);err != nil {
		fmt.Errorf("err : %v",err)
	}

	m := config.Map()
	fmt.Println(len(m))
	for k,v := range config.Map() {
		fmt.Println(k,v)
	}


	// 将配置写入结构体
	var conf Config
	config.Scan(&conf)
	fmt.Println("sssssssssssss",conf)
}

type Host struct {
	Address string `json:"address"`
	Port int `json:"port"`
}

type Config struct{
	Hosts map[string]Host `json:"hosts"`
}
